<template>
  <div class="app-container">
    查询表单
    <el-form :inline="true" class="demo-form-inline">
      <el-form-item>
        <el-input v-model="informationQuery.UID" placeholder="UID" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="informationQuery.field" placeholder="语法/语义" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="informationQuery.sentenceGood" placeholder="好句子" />
      </el-form-item>
      <el-form-item>
        <el-input v-model="informationQuery.sentenceBad" placeholder="坏句子" />
      </el-form-item>
      <el-button type="primary" icon="el-icon-search" @click="getList()">查询</el-button>
      <el-button type="default" @click="resetData()">清空</el-button>
    </el-form>

    <!-- 表格 -->
    <el-table :data="list1" border fit highlight-current-row>
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column prop="datasetInfo" label="所属数据集名/ID" width="100" />
      <el-table-column prop="field" label="语法/语义" width="100" />
      <el-table-column prop="linguisticsTerm" label="语言学术语" width="100" />
      <el-table-column prop="sentenceBad" label="坏句子" width="150" />
      <el-table-column prop="sentenceGood" label="好句子" width="150" />
      <el-table-column prop="uid" label="uid" width="100" />
      <el-table-column prop="createTime" label="创建时间" width="150" />
      <el-table-column prop="updateTime" label="修改时间" width="150" />
      <el-table-column label="操作" width="200" align="center">
        <template slot-scope="scope">
          <router-link :to="'/example/edit/' + scope.row.id + '?belongId=' + getBelongId(scope.row.datasetInfo)">
            <el-button type="primary" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="danger" size="mini" icon="el-icon-delete"
            @click="removeDataById(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination :current-page="page" :page-size="limit" :total="list.page.totalElements"
      style="padding: 30px 0; text-align: center;" layout="total, prev, pager, next, jumper"
      @current-change="getList" />

  </div>
</template>
<script>
//引入调用js文件
import information from '@/api/edu/exampInfo'

export default {
  //写核心代码位置
  // data:{
  // },
  data() { //定义变量和初始值
    return {
      value: '',
      //查询之后接口返回集合
      list: {
        page: {
          totalElements: 0
        }
      },
      list1: [],
      page: 1,//当前页
      limit: 10,//每页记录数
      total: 0,//总记录数
      informationQuery: {} //条件封装对象
    }
  },
  created() { //页面渲染之前执行，一般调用methods定义的方法
    //调用
    this.getList()
  },
  methods: {  //创建具体的方法，调用teacher.js定义的方法
    //列表的方法
    getList(page = 1) {
      this.page = page
      information.getInformationListPage(this.page, this.limit, this.informationQuery)
        .then(response => {//请求成功
          //response接口返回的数据

          this.list = response.data
          this.list1 = this.list.page.content
          console.log(this.list)
          console.log(this.list1)
          // console.log(this.total)
        })
        .catch(error => { console.error(); })//请求失败
    },
    resetData() {//清空的方法
      //表单输入项数据清空
      this.informationQuery = {}
      //查询所有数据
      this.getList()
    },
    //删除的方法
    removeDataById(id) {
      this.$confirm('此操作将永久删除信息记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {  //点击确定，执行then方法
        //调用删除的方法
        information.deleteInformationId(id)
          .then(response => {//删除成功
            //提示信息
            this.$message({
              type: 'success',
              message: '删除成功!'
            });
            //回到列表页面
            this.getList()
          })
      }) //点击取消，执行catch方法
    },
    // 解析字符串，获取数据集id
    getBelongId(datasetInfo) {
      // console.log("index.vue -> belongId: ", datasetInfo.split("/")[1])
      return datasetInfo.split("/")[1]
    }

  }
}
</script>
